var RSA = require('./wx_rsa.js')
const app = getApp()
function encrypt (argument) {
  let string = JSON.stringify(argument)
  console.log(string)
  var publickey = app.globalData.publickey
  let len = string.length
  let end = 0
  let temp = ""
  let jsa = []
  let en = ""
  var encrypt_rsa = new RSA.RSAKey()
  encrypt_rsa = RSA.KEYUTIL.getKey(publickey)
  for(let j = 0; j < len; j++) {
    end = j + 30
    if(end > len) {
      end = len
    }
    temp = string.substring(j, end+1)
    en = encrypt_rsa.encrypt(temp)
    en = RSA.hex2b64(en);
    jsa.push(en)
    j = end
  }
  let params = {
    data: jsa,
    token: app.globalData.token
  }
  return params
}

module.exports = {
  encrypt: encrypt,
}
